import service from '@/utils/request'

// @Tags Goods
// @Summary 创建物品管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Goods true "创建物品管理"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /goods/createGoods [post]
export const createGoods = (data) => {
  return service({
    url: '/goods/createGoods',
    method: 'post',
    data
  })
}

// @Tags Goods
// @Summary 删除物品管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Goods true "删除物品管理"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /goods/deleteGoods [delete]
export const deleteGoods = (data) => {
  return service({
    url: '/goods/deleteGoods',
    method: 'delete',
    data
  })
}

// @Tags Goods
// @Summary 批量删除物品管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除物品管理"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /goods/deleteGoods [delete]
export const deleteGoodsByIds = (data) => {
  return service({
    url: '/goods/deleteGoodsByIds',
    method: 'delete',
    data
  })
}

// @Tags Goods
// @Summary 更新物品管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Goods true "更新物品管理"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /goods/updateGoods [put]
export const updateGoods = (data) => {
  return service({
    url: '/goods/updateGoods',
    method: 'put',
    data
  })
}

// @Tags Goods
// @Summary 用id查询物品管理
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query model.Goods true "用id查询物品管理"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /goods/findGoods [get]
export const findGoods = (params) => {
  return service({
    url: '/goods/findGoods',
    method: 'get',
    params
  })
}

// @Tags Goods
// @Summary 分页获取物品管理列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.PageInfo true "分页获取物品管理列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /goods/getGoodsList [get]
export const getGoodsList = (params) => {
  return service({
    url: '/goods/getGoodsList',
    method: 'get',
    params
  })
}

// @Tags Goods
// @Summary 下载物品清单信息excel
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.PageInfo true "物品管理的excel导出"
// @Success 200 {Blob} Blob 
// @Router /goods/downGoodsExcel [post]
export const downGoodsExcel = async(data) => {
  const res=await service({
    url: '/goods/downGoodsExcel',
    method: 'post',
    data,
    responseType: "blob",
  })
  if (res === undefined){
    return
  }
  let blobUrl = window.URL.createObjectURL(new Blob([res.data], {
      type: "application/vnd.ms-excel",
  }))
  const a = document.createElement("a");
  a.style.display = "none";
  a.download = "物品信息.xlsx";
  a.href = blobUrl;
  a.click();
}

